<?php
//专题商品
class Controller_Admin_TopicGoods extends Controller_Form
{
    public function __construct ($req, $res)
    {
        $this->_form_type = 'topic_goods';
        parent::__construct($req, $res);

        $this->_list_where = array(
        );

        $this->_sort_extra_columns = array(
            array('changed', DB::expr('curdate()')),
        );
    }

	//默认首页
    public function action_index ()
    {
        $this->action_list();
    }

	//添加专题商品
    public function action_create ()
    {
        $post = $this->request->post();
        if (! empty($post))
        {
            $this->rebuild_post_data($post);
            $this->_form_data = $post;
        }

        parent::action_create();
    }

	//修改专题商品
	//$nid int 商品id
    public function action_update ($nid)
    {
        $post = $this->request->post();
        if (! empty($post))
        {
            $this->rebuild_post_data($post);
            $this->_form_data = $post;
        }
        else
        {
            $data = App_TopicGoods::detail($nid);
            $this->_form_data = $data;
        }

        parent::action_update($nid);
    }

	//专题商品详细信息
    public function action_detail ($nid)
    {
        $data = App_TopicGoods::detail($nid);
        $this->_form_data = $data;

        parent::action_detail($nid);
    }

	//构造post数组
    private function rebuild_post_data (& $post)
    {
        $post['uid']   = user::current_user_id();
    }

    public function list_filter_data (& $rows)
    {
    }

	//显示商品
    public function list_get_data ($offset, $limit)
    {
        $catid = $this->request->query('topicId');
        return App_TopicGoods::items($catid, $offset, $limit);

        return NULL;
    }
}
